package com.ruoyi.mq.service.serviceImpl.Processor;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.mq.service.MessageProcessor;
import com.ruoyi.system.domain.GwHomeSummarize;
import com.ruoyi.system.service.IGwHomeSummarizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ProductInfoProcessor implements MessageProcessor {

    @Autowired
    private IGwHomeSummarizeService gwHomeSummarizeService;
    @Override
    public void processMessage(JSONObject message) {
        // 处理产品信息
        String tag = message.getString("tag");
        String niot = message.getString("niot");
        String data = message.getString("data");
//        GwHomeSummarize gwHomeSummarize = gwHomeSummarizeService.selectGwHomeSummarizeByNodeIdentifier(niot);
//        //如果首页汇总记录为空，则新增首页汇总
//        if (gwHomeSummarize==null){
//            GwHomeSummarize gwHomeSummarize1 =new GwHomeSummarize();
//            gwHomeSummarize1.setNodeIdentifier(tag);
//            gwHomeSummarize1.setProductCategoriesNumber(Long.valueOf(data));
//            gwHomeSummarizeService.insertGwHomeSummarize(gwHomeSummarize1);
//            return;
//        }
        GwHomeSummarize gwHomeSummarize =new GwHomeSummarize();
        gwHomeSummarize.setNodeIdentifier(niot);
        gwHomeSummarize.setCreateTime(new Date());

            //产品对象相加
            gwHomeSummarize.setProductCategoriesNumber(Long.valueOf(data));
            gwHomeSummarizeService.insertGwHomeSummarize(gwHomeSummarize);
        //产品对象相减
//            gwHomeSummarize.setProductCategoriesNumber(gwHomeSummarize.getProductCategoriesNumber()==null?Long.valueOf(data):gwHomeSummarize.getProductCategoriesNumber()-Long.valueOf(data));
//            gwHomeSummarizeService.updateGwHomeSummarize(gwHomeSummarize);
//
//


    }
}
